package B刷题.A栈和队列;

import java.util.Stack;

/**
 * @author wei.zhao
 * @description: 剑指 Offer 09.用两个栈实现队列
 * @date 2022/12/2 10:11
 */
public class Code03_CQueue {

    /**
     * 充分利用栈的特点：先进后出
     */
    Stack<Integer> addstack;
    Stack<Integer> popStack;

    public Code03_CQueue() {
        addstack = new Stack<>();
        popStack = new Stack<>();
    }

    public void appendTail(int value) {
        addstack.add(value);
    }

    public int deleteHead() {
        if (addstack.isEmpty() && popStack.isEmpty()) {
            return -1;
        }
        if (!popStack.isEmpty()) {
            return popStack.pop();
        } else {
            while (!addstack.isEmpty()) {
                popStack.add(addstack.pop());
            }
            return popStack.pop();
        }
    }

}
